home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / rexx / spellblock.epxx < prev    next >
Text File  |  1996-07-27  |  6KB  |  204 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*     File : SpellBlock.epxx                                           */
  4. /*   Author : Martin Reddy                                              */
  5. /*  Version : 1.2                                                       */
  6. /*     Date : 10/2/95                                                   */
  7. /*  Purpose : An ARexx script used to control the text editor EdWord    */
  8. /*     Note : This is part of the Spell Checking facility of EdWord     */
  9. /* Function : This script file will check the spelling for the          */
  10. /*            currently selected block of text. (see below for          */
  11. /*            customisation).                                           */
  12. /*  Updates : [27/7/96] - Cleaned up ProgInd, added more error checking */
  13. /*                                                                      */
  14. /************************************************************************/
  15.  
  16.     /* Set IGNORE_VALID_ROOTS to TRUE if you want the spell check to
  17.        ignore words which aren't in the dictionary, but do have a
  18.        valid root, e.g. ignore WASTED if the word WASTE exists in the
  19.        dictionary. This reduces the need to have every tense of a
  20.        word, and plurals, to be explicitly stored in the dictionary */
  21.         
  22.     IGNORE_VALID_ROOTS = TRUE
  23.  
  24.                                       
  25.     /*-------------- Nothing To Change Below Here -----------*/
  26.  
  27.     HOST = ADDRESS()
  28.     ADDRESS VALUE HOST
  29.  
  30.     OPTIONS RESULTS
  31.  
  32.     /****** Make sure there is a block to spell check first ******/
  33.  
  34.     IsSelected
  35.     IF ( RESULT == 0 ) THEN DO
  36.         Inform "No Block Has Been Currently Defined|Please Drag Select Region First."
  37.         EXIT
  38.     END
  39.  
  40.     /********** Make sure that the ISpell process is up *********/
  41.  
  42.     IF ~SHOW( PORTS, 'IRexxSpell' ) THEN DO
  43.         Message "Loading Dictionary..."
  44.         ADDRESS COMMAND 'run <nil: >nil: EdSpell:ISpell/ispell -r >nil: <nil:'
  45.         ADDRESS COMMAND 'EdSpell:ISpell/WaitForPort IRexxSpell'
  46.         IF RC ~= 0 THEN DO
  47.             Inform "Could Not Start ISpell Process|Spell Check Aborted!"
  48.             Message ""
  49.             EXIT
  50.         END
  51.     END
  52.  
  53.     /**************** Get a Word From The User *****************/
  54.  
  55.     Message "Spell Checking Block..."
  56.     SetView OFF
  57.     ProgressIndicator
  58.  
  59.     GetEOLWrap; EOLSAVE=RESULT; SetEOLWrap ON
  60.  
  61.     JumpToBlock
  62.     GetWord; WORD = UPPER(RESULT)
  63.  
  64.     IsInBlock
  65.     DO UNTIL RESULT == 0
  66.  
  67.         CALL CheckWord(WORD)
  68.  
  69.         GetNextWord
  70.         IF RC ~= 0 THEN LEAVE
  71.         WORD = UPPER(RESULT)
  72.  
  73.         IsInBlock
  74.  
  75.     END
  76.  
  77.     /**************** All done now: quit... ****************/
  78.  
  79.     CALL CloseDown
  80.     Inform "End of Block Reached|Spell Check Completed."
  81.     EXIT
  82.  
  83.     /************ PROCEDURE: "CloseDown" ************/
  84.  
  85.     CloseDown: PROCEDURE EXPOSE EOLSAVE
  86.         SetEOLWrap EOLSAVE
  87.         ProgressIndicator
  88.         SetView ON
  89.         Message ""
  90.     RETURN
  91.  
  92.     /************ PROCEDURE: "AbortSpellCheck" ************/
  93.  
  94.     AbortSpellCheck: PROCEDURE
  95.         CHOICE "Do You Really Want To|Terminate This Spell Check?@@Yes, Stop|No, Continue"
  96.         IF RC == 1 THEN DO
  97.             CALL CloseDown
  98.             EXIT
  99.         END
  100.         MovePrevWord
  101.     RETURN
  102.  
  103.     /************ PROCEDURE: "HighlightWord" ************/
  104.  
  105.     HighlightWord: PROCEDURE
  106.         MoveRight
  107.         MovePrevWord
  108.         ProgressIndicator
  109.         SetView ON
  110.     RETURN
  111.  
  112.     /************ PROCEDURE: "AddWord(word)" ************/
  113.  
  114.     AddWord: PROCEDURE
  115.     PARSE ARG THEWORD
  116.         Choice "Please Confirm The Addition of|"||THEWORD||" To The Dictionary.@@Add Word|Cancel"
  117.         IF RC ~= 0 THEN DO
  118.             ADDRESS "IRexxSpell" ADD THEWORD
  119.         END
  120.     RETURN
  121.  
  122.     /************** PROCEDURE: TurnOffView ****************/
  123.  
  124.     TurnOffView: PROCEDURE
  125.         Message "Spell Checking Block..."
  126.         SetView OFF
  127.         ProgressIndicator
  128.     RETURN
  129.  
  130.     /************ PROCEDURE: "CheckWord(word)" ************/
  131.  
  132.     CheckWord: PROCEDURE EXPOSE IGNORE_VALID_ROOTS
  133.     PARSE ARG SEARCHWORD
  134.  
  135.         SEARCHWORD = COMPRESS( SEARCHWORD, '~`,./<>?;:"[]{}!@#$%^&*()+|=\- ' )
  136.         IF SEARCHWORD == '' THEN RETURN
  137.  
  138.         INTERACT = FALSE
  139.  
  140.         ADDRESS "IRexxSpell" CHECK SEARCHWORD
  141.         WORD = RESULT
  142.  
  143.         IF WORD == "*" THEN DO
  144.             RETURN
  145.         END; ELSE IF LEFT(WORD,1) == "+" THEN DO
  146.             IF IGNORE_VALID_ROOTS == TRUE THEN RETURN
  147.             CALL HighlightWord
  148.             PARSE VAR WORD DUMMY ROOT
  149.             Choice SEARCHWORD" Is A Valid Combination|But Is Not In Dictionary|(Root Word Is:"||ROOT||")@@Ignore|Stop|Add Word"
  150.             IF RC == 0 THEN DO
  151.                 CALL AddWord(SEARCHWORD)
  152.             END; ELSE IF RC == 2 THEN DO
  153.                 CALL AbortSpellCheck
  154.             END
  155.             CALL TurnOffView
  156.         END; ELSE IF LEFT(WORD,1) == "&" THEN DO
  157.             CALL HighlightWord
  158.             PARSE VAR WORD DUMMY SUGA SUGB SUGC SUGD SUGE
  159.  
  160.             SUG = "|1) "SUGA
  161.             IF (SUGB ~= "END") & (SUGB ~= "") & (SUGB ~= "SUGB") THEN DO
  162.                 SUG = SUG||"|2) "||SUGB
  163.             END
  164.             IF (SUGC ~= "END") & (SUGC ~= "") & (SUGC ~= "SUGC") THEN DO
  165.                 SUG = SUG||"|3) "||SUGC
  166.             END
  167.             IF (SUGD ~= "END") & (SUGD ~= "") & (SUGD ~= "SUGD") THEN DO
  168.                 SUG = SUG||"|4) "||SUGD
  169.             END
  170.  
  171.             INTERACT = TRUE
  172.             PROMPT = "'"||SEARCHWORD||"' Not In Dictionary|Possible Suggestions Are:|"||SUG
  173.         END; ELSE DO
  174.             CALL HighlightWord
  175.             INTERACT = TRUE
  176.             PROMPT = "'"||SEARCHWORD||"' Not In Dictionary|No Possible Suggestions Found"
  177.         END
  178.  
  179.         IF INTERACT == TRUE THEN DO
  180.             Choice PROMPT||"@@Ignore|Add/Edit|Stop"
  181.             IF RC == 0 THEN DO
  182.                 CALL AbortSpellCheck
  183.             END; ELSE IF RC == 2 THEN DO
  184.                 Choice "Word = '"||SEARCHWORD||"'||  Edit = Edit Current Word     |   Add = Add Word To Dictionary|Cancel = Continue Spell Check  @@Edit|Add|Cancel"
  185.  
  186.                 IF RC == 1 THEN DO
  187.                     GetInput "Type New Spelling For Word (Blank=Abort)"
  188.                     NEWWORD = RESULT
  189.                     IF NEWWORD ~= "RESULT" & NEWWORD ~= "" THEN DO
  190.                         DeleteWord
  191.                         InsertText D2C(34)||NEWWORD||" "||D2C(34)
  192.                         MovePrevWord
  193.                     END
  194.                 END; ELSE IF RC == 2 THEN DO
  195.                     CALL AddWord(SEARCHWORD)
  196.                 END
  197.  
  198.             END
  199.             CALL TurnOffView
  200.         END
  201.  
  202.     RETURN
  203.  
  204.